﻿using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Model;
using YouHP.BLL;
using YouHP.Utility;

namespace YouHP.Pages.Member
{
    public class TreatmentRecordes : PatientBasePage
    {
        
        protected string RecordDate {get; set;}
        

        //private Dictionary<int, int> _TreatmentRecordData;
        //protected string 

        protected override void ShowPage()
        {
            base.ShowPage();
            if (ErrorCount > 0) return;

            HandleCommon();

            if (IsPost) HandlePost();
            else HandleGet();
        }

        protected void HandleCommon()
        {
                
        }

        protected void HandleGet()
        {
            //int id = RequestTools.GetQueryInt("id", 0);
            //if (id > 0) TreatmentRecordInfo = PatientBLL.Instance.GetTreatmentRecordes(id, PRInfo.Id);
            //if (TreatmentRecordInfo == null) TreatmentRecordInfo = new PatientSymptomInfo();
            //if (TreatmentRecordInfo.Id <= 0)
            //{
            //    RecordDate = "";
            //}
            //else
            //{
            //    RecordDate = TreatmentRecordInfo.RecordDate.ToString("yyyy-MM-dd");
            //    this.SetTreatmentRecordData(SymptomRecordInfo.SymptomInfo);
            //}
        }

        protected void HandlePost()
        {
            SymptomRecordesInfo info = new SymptomRecordesInfo();
            info.Id = RequestTools.GetFormInt("symrecordid",-1);
            bool isCreated = true;
            if (info.Id <= 0) isCreated = false;
            info.PatientRecordId = PRInfo.Id;
            StringBuilder sb = new StringBuilder();
            //foreach (DiseaseSymptomInfo syminfo in PrimarySymptomList)
            //{
            //    sb.AppendFormat("@{0}={1}", syminfo.SymptomId, RequestTools.GetFormString("sym" + syminfo.SymptomId));
            //}
            //foreach (DiseaseSymptomInfo syminfo in SecondSymptomList)
            //{
            //    sb.AppendFormat("@{0}={1}", syminfo.SymptomId, RequestTools.GetFormString("sym" + syminfo.SymptomId));
            //}
            info.SymptomInfo = sb.ToString();
            info.Remark = RequestTools.GetFormString("remark");
            info.RecordDate = Convert.ToDateTime(RequestTools.GetFormString("recorddate"));
            info.UpdateDate = DateTime.Now;
            if (isCreated)
            {
                PatientBLL.Instance.UpdateSymptomRecordes(info);
                this.AddMsgLine("更新症状记录成功");
                this.SetUrl("ListSymptomRecordes.aspx");
            }
            else
            {
                PatientBLL.Instance.AddSymptomRecordes(info);
                this.AddMsgLine("添加症状记录成功");
                this.SetUrl("ListSymptomRecordes.aspx");
            }
            
        }

        private void SetTreatmentRecordData(string datastr)
        {
            //if (_TreatmentRecordData == null) _SymptomRecordData = new Dictionary<int, int>();
            //_TreatmentRecordData.Clear();
            //string[] spliter = new string[] { "@" };
            //string[] spliter2 = new string[] { "=" };
            //string[] datapair = datastr.Split(spliter,StringSplitOptions.RemoveEmptyEntries);
            //foreach (string str in datapair)
            //{
            //    string[] strArray = str.Split(spliter2, StringSplitOptions.RemoveEmptyEntries);
            //    int key = Convert.ToInt32(strArray[0]);
            //    int val = Convert.ToInt32(strArray[1]);
            //    _TreatmentRecordData.Add(key, val);
            //}
        }
        protected string GetTreatmentRecordData(int key)
        {
            //if (_TreatmentRecordData == null) return "";
            //if (_TreatmentRecordData.ContainsKey(key) == false) return "";
            //string data = _TreatmentRecordData[key];
            //return data;
            return "";
        }
    }
}
